<template>
  <a-card :bordered="false">
    <!-- table区域-begin -->
    <div>
      <vxe-grid
        style="width: 100%;"
        :height="curHeight"
        size="mini"
        align="center"
        highlight-hover-row
        stripe
        row-key
        row-id="selectedRowKeys"
        column-min-width="150"
        id="id"
        keep-source
        :loading="loading"
        border
        resizable
        auto-resize
        showOverflow
        showHeaderOverflow
        :pager-config="tablePage"
        ref="xGrid"
        :row-config="{ useKey: true,keyField: 'id',isCurrent:true,isHover:true}"
        :checkbox-config="{
          checkRowKeys:selectedRowKeys,
          trigger: 'row',
          highlight: true,
          reserve: true}"
        @sort-change="sortChange"
        @checkbox-change="checkboxChangeEvent"
        @checkbox-all="checkboxChangeEvent"
        :data="dataSource"
        :columns="columns"
        @page-change="handlePageChange"
      >
        <template v-slot:top>
          <div class="table-operator">
            <a-button type="primary" icon="plus" @click="handleAdd">新增</a-button>
            <!-- 高级查询区域 -->
            <j-super-query :fieldList="superFieldList" ref="superQueryModal"
                           @handleSuperQuery="handleSuperQuery"></j-super-query>
            <a-dropdown v-if="selectedRowKeys.length > 0">
              <a-menu slot="overlay">
                <a-menu-item key="1" @click="batchDel">
                  <a-icon type="delete"/>
                  删除
                </a-menu-item>
              </a-menu>
              <a-button type="primary" icon="down">批量操作</a-button>
            </a-dropdown>
          </div>
        </template>
        <template v-slot:operate="{ row }">
          <a-button v-if="row.status == 0" type="primary" shape="circle" @click="handleEdit(row)" icon="edit"/>
          <a-button v-else type="primary" shape="circle" @click="handleEdit(row)" icon="edit" disabled/>
          <a-divider type="vertical"/>
          <a-dropdown>
            <a-button type="primary" shape="circle" class="ant-dropdown-link" icon="setting"/>
            <a-menu slot="overlay">
              <a-menu-item>
                <a @click="handleDetail(row)">详情</a>
              </a-menu-item>
            </a-menu>
          </a-dropdown>
        </template>
        <template v-slot:statusRender="{ row }">
          <a-switch :checked="row.status == 1" checked-children="生效" un-checked-children="失效"
                    @change="onChange(row)"></a-switch>
        </template>
        <template v-slot:empty>
          <a-empty/>
        </template>
      </vxe-grid>
    </div>
    <!-- table区域-end -->
    <wms-outbound-config-modal ref="modalForm" @ok="modalFormOk"></wms-outbound-config-modal>
  </a-card>
</template>

<script>

import '@/assets/less/TableExpand.less'
import {mixinDevice} from '@/utils/mixin'
import {HYListMixin} from '@/mixins/HYListMixin'
import WmsOutboundConfigModal from './modules/WmsOutboundConfigModal'
import {putAction} from "@api/manage";

export default {
  name: 'WmsOutboundConfigList',
  mixins: [HYListMixin, mixinDevice],
  components: {
    WmsOutboundConfigModal
  },
  data() {
    return {
      description: '出库配置管理页面',
      // 表头
      columns: [
        {type: "checkbox", width: 50, align: "center"},//多选
        {type: "seq", width: 50, align: "center"},//
        {title: '编码', align: "center", field: 'code'},
        {title: '名称', align: "center", field: 'name'},
        {title: '订单类型', align: "center", field: 'orderType_dictText'},
        {title: '状态', align: "center", field: 'status',slots: {default: 'statusRender'}},
        {title: '发货同步ERP', align: "center", field: 'shipSycErp_dictText'},
        {title: '限排', align: "center", field: 'limitXpos'},
        {title: '限列', align: "center", field: 'limitYpos'},
        {title: '限层', align: "center", field: 'limitLayer'},
        {title: '限重', align: "center", field: 'limitWeight'},
        {title: '限高', align: "center", field: 'limitHeight'},
        {title: '操作', fixed: 'right', width: 105, slots: {default: 'operate'}}
      ],
      url: {
        list: "/wcs/wcsOutboundConfig/list",
        changeStatus: "/wcs/wcsOutboundConfig/edit",
        delete: "/wcs/wcsOutboundConfig/delete",
        deleteBatch: "/wcs/wcsOutboundConfig/deleteBatch",
        exportXlsUrl: "/wcs/wcsOutboundConfig/exportXls",
        importExcelUrl: "wcs/wcsOutboundConfig/importExcel",
      },
      dictOptions: {},
      superFieldList: [],
    }
  },
  created() {
    this.getSuperFieldList();
  },
  computed: {
    importExcelUrl: function () {
      return `${window._CONFIG['domianURL']}/${this.url.importExcelUrl}`;
    },
  },
  methods: {
    onChange(row) {
      let status = row.status;
      status = status == '1' ? false : true;
      row.status = status;
      putAction(this.url.changeStatus, row).then((res) => {
        if (res.success) {
          this.$message.success(res.message);
        } else {
          this.$message.warning(res.message);
        }
      }).finally(() => {
        this.modalFormOk();
      })
    },
    getSuperFieldList() {
      let fieldList = [];
      fieldList.push({type: 'string', value: 'code', text: '编码', dictCode: ''})
      fieldList.push({type: 'string', value: 'name', text: '名称', dictCode: ''})
      this.superFieldList = fieldList
    }
  }
}
</script>
